package com.lucky.system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lucky.system.dao.TagDao;
import com.lucky.system.domain.TagDO;
import com.lucky.system.service.TagService;



@Service
public class TagServiceImpl implements TagService {

	@Autowired
	private TagDao tagDao;
	
	@Override
	public TagDO get(Integer tagId){
		return tagDao.get(tagId);
	}
	
	@Override
	public List<TagDO> list(Map<String, Object> map){
		return tagDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return tagDao.count(map);
	}
	
	@Override
	public int save(TagDO tag){
		return tagDao.save(tag);
	}
	
	@Override
	public int update(TagDO tag){
		return tagDao.update(tag);
	}
	
	@Override
	public int remove(Integer tagId){
		return tagDao.remove(tagId);
	}
	
	@Override
	public int batchRemove(Integer[] tagIds){
		return tagDao.batchRemove(tagIds);
	}

	@Override
	public void setTag(String[] tags) {
		for (int i = 0; i < tags.length; i++) {
			String tag = tags[i];
			Map<String, Object> map = new HashMap<>();
			map.put("tagName",tag);
			int count = tagDao.count(map);
			if(count == 0){
				TagDO tagDO = new TagDO(tag,1);
				tagDao.save(tagDO);
			}
		}
	}
}
